#include<iostream>
using namespace std;
const int N=1010;
int lose[N],win[N],n,x;
int need[N];
int dp[N][N];
int dfs(int l,int spx)
{
    if(dp[l][spx])return dp[l][spx];
    if(l>n)
    {
        return 0;
    }
    int sum=0;
    if(spx<need[l])
    {
        sum=dfs(l+1,spx)+lose[l];
    }else
    {
    sum=max(dfs(l+1,spx)+lose[l],dfs(l+1,spx-need[l])+win[l]);
    }
    dp[l][spx]=sum;
    return sum;
}
int main()
{
cin>>n>>x;
for(int i=1;i<=n;i++)cin>>lose[i]>>win[i]>>need[i];
int ans=dfs(1,x);
cout<<(long long)5*ans;
    return 0;
}